//
// Created by Administrator on 2023/11/15.
//
#include "iostream"
#include "string"

using namespace std;

const int N = 1e5 + 10;

int n, m;
int A[N];

// 路径压缩
int find(int x) {
    if (A[x] < 0) return x;
    A[x] = find(A[x]);
}

//按size合并
void merge(int a, int b) {
    if (-A[find(a)] >= -A[find(b)])
        A[find(b)] = find(a);
    else
        A[find(a)] = find(b);
    A[find(b)]--;
}


int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        A[i] = -1;


    string ch;
    int a, b;
    while (m--) {
        cin >> ch;
        if (ch == "C") {
            cin >> a >> b;
            merge(a, b);
        } else if (ch == "Q1") {
            cin >> a >> b;
            cout << ((find(a) == find(b)) ? "Yes" : "No") << endl;
        } else {
            cin >> a;
            int size = A[find(a)];;
            cout << -size << endl;
        }
    }

}